package off_transaction

import (
	// "bp/cache"
	sqlc "bp/db/sqlc"
	// "bp/internal/util"
	"context"
)

// DisableOffTransactionByOutTransNoAndOutOrderNo 根据外部交易号+外部订单号作废优惠交易
func (s *OffTransactionEntityServiceImp) DisableOffTransactionsByOutTransNo(ctx context.Context, q *sqlc.Queries, outTransNo string) (err error) {
	// slog := util.NewContextLogger(ctx, s.slog)
	err = q.DisableOffTransactionsByOutTransNo(ctx, outTransNo)
	if err != nil {
		return
	}
	return
}

// DisableOffTransactionByOutTransNoAndOutOrderNoParam 根据外部交易号+外部订单号
type DisableOffTransactionByOutTransNoAndOutOrderNoParam struct {
	OutTransNo string
	OutOrderNo string
}

// DisableOffTransactionByOutTransNoAndOutOrderNo 根据外部交易号+外部订单号作废优惠交易
func (s *OffTransactionEntityServiceImp) DisableOffTransactionsByOutTransNoAndOutOrderNo(ctx context.Context, q *sqlc.Queries, ptr *DisableOffTransactionByOutTransNoAndOutOrderNoParam) (err error) {
	// slog := util.NewContextLogger(ctx, s.slog)
	err = q.DisableOffTransactionsByOutTransNoAndOutOrderNo(ctx, sqlc.DisableOffTransactionsByOutTransNoAndOutOrderNoParams{
		OutTransNo: ptr.OutTransNo,
		OutOrderNo: ptr.OutOrderNo,
	})
	if err != nil {
		return
	}
	return
}

// UpsertOffTransaction 新建/更新优惠交易
func (s *OffTransactionEntityServiceImp) UpsertOffTransaction(ctx context.Context, q *sqlc.Queries, ptr *sqlc.UpsertOffTransactionParams) (offTransactionPtr *sqlc.OffTransaction, err error) {
	// slog := util.NewContextLogger(ctx, s.slog)
	offTransaction, err := q.UpsertOffTransaction(ctx, *ptr)
	if err != nil {
		return
	}
	offTransactionPtr = &offTransaction
	return
}

// MarkOffTransactionOutTransDoneByOutTransNo 标记外部交易号相关的交易记录已完成
func (s *OffTransactionEntityServiceImp) MarkOffTransactionDoneByOutTransNo(ctx context.Context, q *sqlc.Queries, outTransNo string) (err error) {
	// slog := util.NewContextLogger(ctx, s.slog)
	err = q.MarkOffTransactionDoneByOutTransNo(ctx, outTransNo)
	if err != nil {
		return
	}
	return
}

// MarkOffTransactionApportioned 标记交易记录已分摊
func (s *OffTransactionEntityServiceImp) MarkOffTransactionApportioned(ctx context.Context, q *sqlc.Queries, transactionID int64) (err error) {
	// slog := util.NewContextLogger(ctx, s.slog)
	err = q.MarkOffTransactionApportioned(ctx, transactionID)
	if err != nil {
		return
	}
	return
}

// MarkOffTransactionApportionmentsSended 标记交易分摊记录已被发送
func (s *OffTransactionEntityServiceImp) MarkOffTransactionApportionmentsSended(ctx context.Context, q *sqlc.Queries, transactionID int64) (err error) {
	// slog := util.NewContextLogger(ctx, s.slog)
	err = q.MarkOffTransactionApportionmentsSended(ctx, transactionID)
	if err != nil {
		return
	}
	return
}